package com.example.drzhang.oengldemo.data;

import android.opengl.GLES20;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

/**
 * Created by drzhang on 2018/1/10.
 */

public class VertexArray {

    private FloatBuffer mFloatBuffer;

    public VertexArray(float[] vertexData){
        mFloatBuffer = ByteBuffer.allocateDirect(vertexData.length * Constant.BYTES_PER_FLOAT)
                                 .order(ByteOrder.nativeOrder())
                                 .asFloatBuffer()
                                 .put(vertexData);
    }

    public void setVertexAttribPointer(int dataOffset, int attributeLocation, int componentCount, int stride){
        mFloatBuffer.position(dataOffset);
        GLES20.glVertexAttribPointer(attributeLocation,componentCount,GLES20.GL_FLOAT,false,stride,mFloatBuffer);
        GLES20.glEnableVertexAttribArray(attributeLocation);
        mFloatBuffer.position(0);
    }


}
